package com.projecti18n;

import java.io.IOException;
import java.io.Writer;
import java.util.Properties;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IORuntimeException;
import cn.hutool.core.io.IoUtil;

public class Props extends Properties {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/**
	 * 持久化当前设置，会覆盖掉之前的设置
	 * 
	 * @param absolutePath 设置文件的绝对路径
	 * @throws IORuntimeException IO异常，可能为文件未找到
	 */
	public void store(String absolutePath) throws IORuntimeException{
		Writer writer = null;
		try {
			writer = FileUtil.getWriter(absolutePath, "UTF-8", false);
			super.store(writer, null);
		} catch (IOException e) {
			throw new IORuntimeException(e, "Store properties to [{}] error!", absolutePath);
		} finally {
			IoUtil.close(writer);
		}
	}
}
